<!--  -->
<template>
  <div class="order">
    <van-nav-bar
      title="确认订单"
      left-text="返回"
      fixed
      @click-left="$router.back()"
    >
    </van-nav-bar>
    <van-cell :title="pdsss ? ximdh:'请选择收货地址'" :label="pdsss ? xidzz : ''" is-link class="hfdkfkd" @click="shuoddzzzz"/>

    <div class="gdffd">
      <van-card
        v-for="item in jissdx"
        :key="item.id"
        :num="item.count"
        :price="item.price.toFixed(2)"
        :title="item.name"
        :thumb="item.cover"
      />
    </div>

    <van-submit-bar :price="zongjiag" button-text="付款"  @submit="onSubmit">
      <span>共计{{hejishul}}件</span>
    </van-submit-bar>

    <mima ref="fffff" :djfd="fdfd" ></mima>
  </div>
</template>

<script>
import lsccshujzhu from "@/utll/strong/strong.js";
import { mapState } from "vuex";
import Mima from '../../components/mima.vue';
import { xiadan } from "network/api.js";

export default {
  name: "",
  data() {
    return {
      jissdx: [],
      fdfdff:{},
      fdfd:0,
      
    };
  },
  components:{Mima},
  computed: {
    ...mapState(['userInfo']),
    pdsss() {
        return !!(this.$route.query.id) || false
    },
    ximdh(){
      let{name,mobile}=this.fdfdff
      return `${name},${mobile}`
    },
     xidzz(){
      let{province,city,country,detail}=this.fdfdff
      return `${province} ${city} ${country} ${detail}`
    },
    hejishul(){
      return this.jissdx.reduce((p,c)=>p+c.count,0)
    },
    zongjiag(){
      return this.jissdx.reduce((p,c)=>p+c.count*c.price,0)*100
    }
  },
  created() {
    this.jissdx = lsccshujzhu.get("spxinxi");
    console.log(this.jissdx)
    const {addressList}=this.userInfo
    this.fdfdff=addressList.filter(item=>item.id==this.$route.query.id)[0]
    console.log(this.fdfdff)
  },

  methods: {
      //去收货地址
      shuoddzzzz(){
          this.$router.push({
              path:'/shouhuodizhi',
              query:{
                  df:'orderdd'
              }
          })
      },
      async onSubmit(){
        if(this.pdsss){
          this.$refs.fffff.showPopup()
          let{id}=this.fdfdff
          let qqspqd=[]
          this.jissdx.forEach(item => {
            let{product_id,name,price,cover,count}=item
            qqspqd.push({product_id,name,price,cover,count})
          });
          console.log(this.fdfdff)
          const {errcode,data}=await xiadan(qqspqd,id)
          if(errcode!=0) return 
          this.fdfd=data.id
          console.log(data)
          
        }else{
           this.$toast('请输入地址');
        }
        
      }
  },
};
</script>
<style lang='less' scoped>
.hfdkfkd {
  position: fixed;
  top: 46px;
  z-index: 999;
}
.gdffd {
  height: calc(100vh - 160px);
  margin-top: 113px;
  -webkit-overflow-scrolling: touch;
  overflow-y: scroll;
}
</style>